﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using CommonMvc.Models;
using CommonMvc.Models.CommonModels;
using CommonMvc.Models.Concreate;

namespace CommonMvc.Controllers
{
    public class RoleController : Controller
    {
        DataContext _context;
        public RoleController(DataContext context) //依赖注入得到实例  
        {
            _context = context;
        }

        public IActionResult Create()
        {
            return View();
        }
        [HttpPost]
        public IActionResult Create(Role item)
        {

            _context.Roles.Add(item);
            _context.SaveChanges();
            return Redirect("List");
        }

        public IActionResult List()
        {
            List<Role> list = null;
           
            list = _context.Roles.ToList();
           
            return View(list);
        }



        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

        protected override void Dispose(bool disposing)
        {
            _context.Dispose();
            base.Dispose(disposing);
        }
    }
}
